package presenters.component

import presenters.test.AssertableBuilder
import presenters.test.TestNode

class MarkupComponentTest extends GroovyTestCase {

    MarkupComponent markup
    def builder

    protected void setUp() {
        super.setUp()
        markup = new MarkupComponent()
        builder = new AssertableBuilder()
        markup.metaClass.builder = builder
    }

    public void testNewLinesInTextCanBeRenderedAsParagraphs() {
        markup.renderText("""paragraph1
paragraph2""")

        assertTrue(builder.hasNodeWith(name:"p", value:"paragraph1"))
        assertTrue(builder.hasNodeWith(name:"p", value:"paragraph2"))
    }

    public void testMultipleConsecutiveNewLinesAreIgnored() {
        markup.renderText("""paragraph1

paragraph2""")

        assertEquals(2, builder.nodesCalled.size())
        assertTrue(builder.hasNodeWith(name:"p", value:"paragraph1"))
        assertTrue(builder.hasNodeWith(name:"p", value:"paragraph2"))        
    }
}